import Axios from "axios";
// @ts-ignore
import {VsNotification} from "vuesax-alpha";
// import type {ResultData} from "@/apis/base";
import config from "@/config";

import type {PositionType,NotifyColor} from "@/plugins/Notify";

console.log(config)
const mainAxios = Axios.create({
	baseURL: config.api.baseUrl,
	responseType:'json',
	timeout: Number(config.request.timeout)
})
interface NotifyParam {
	position?: PositionType,
	color?:NotifyColor,
	title:string,
	text:string
}
export const openNotification = ({
	position = 'top-right',
	color ='primary',
	title='标题',
	text='通知文本'
                                 }:NotifyParam) => {
	VsNotification({
		loading: true,
		color,
		position,
		title,
		content: text,
		progressAuto:true
	})
}
mainAxios.interceptors.response.use((resp)=> {
	console.log(resp)
	const resData = resp.data;
	if(resp && resData && resData.code===200){
		return resData
	}else if(resp && resData && resData.code!==200){
		openNotification({
			title:'Error',
			text: resData.msg,
			color: 'danger'
		})
	}else{
		openNotification({
			title:'Error',
			text: '未知异常'
		})
	}
	return new Error('请求失败');
})
export default {
	wallpaperAxios: Axios.create({
		baseURL: 'https://raw.onmicrosoft.cn/Bing-Wallpaper-Action/main/data/zh-CN_all.json'
	}),
	randomWallAxios: Axios.create({
	}),
	mainAxios
}